package com.ruoyi.videoHandler;

import javax.websocket.OnClose;
import javax.websocket.OnError;
import javax.websocket.OnOpen;
import javax.websocket.Session;
import javax.websocket.server.PathParam;
import javax.websocket.server.ServerEndpoint;

/**
 * @projectName: intelligent-monitor
 * @package: org.ruoyi
 * @className: Transmit
 * @author: 寇耕耀
 */
@ServerEndpoint(value = "/transmit")
public class Transmit {
    private Session session;

    //前端请求时一个websocket时
    @OnOpen
    public void onOpen(Session session, @PathParam("userId") String userId) throws Exception {
        this.session = session;
//        webSocketMap.put(userId, this);
        System.out.println("执行setSession2");
        VideoStreamHandler.setSession2(session);
        System.out.println("【websocket消息】有新的连接,连接id=" + userId + ":" + this);
    }

    //前端关闭时一个websocket时
    @OnClose
    public void onClose(@PathParam("userId") String userId) {
//        webSocketMap.remove(userId);
        VideoStreamHandler.setSession2(null);
        System.out.println("【websocket消息】连接断开:" + userId);

    }

    @OnError
    public void onError(Session session, Throwable error) {
        System.out.println("【websocket消息】WebSocket发生错误，错误信息为：" + error.getMessage());
        error.printStackTrace();
    }

}
